<?php

require_once BASE_PATH . 'application/models/itemdao' . EXT;

class categoryDAO extends baseDAO {
    
    var $table = 'k2_categories';
    var $key = 'id';
    
    
    function __construct() {

        // Call the Model constructor
        parent::__construct();
    }


    function _defaultSQL($default = 1) {

        $this->db->where(array("published" => 1, "trash" => 0));
	
    }

    function getSubCategoriesById($id) {

        $this->db->where_in('parent', $id);
	$this->_defaultSQL();
        $query = $this->db->get($this->table);
        return $result = $query->result();
    }

    function getCategoriesById($id) {

        $this->db->where_in('id', $id);
	$this->_defaultSQL();
        $query = $this->db->get($this->table);
        return $result = $query->result();
    }

    function getMainSubCategoriesById($id) {
        $resp = $this->getCategoriesById($id);
        if ($resp[0]->parent != 0)
            $this->db->where_in('parent', $resp[0]->parent);
        else
            $this->db->where_in('parent', $id);
	    
	    $this->_defaultSQL();
        $query = $this->db->get($this->table);
        return $result = $query->result();
    }

	function getMainCategoryById($id){
		$this->db->where('id', $id);
		$this->_defaultSQL();
        $query = $this->db->get($this->table);
        $result = $query->result();
		#print_r($result); die;
		
		if($result[0]->parent <= 7)
			return $result[0]->parent;
	}

}

?>